package com.briup.searchengine.view.web.controller;


import com.briup.searchengine.view.bean.PageBean;
import com.briup.searchengine.view.dao.PageDao;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Set;

@Controller
public class SystemController {


    @GetMapping(value = {"toIndex", "/"})
    public String toIndex() {
        return "index";
    }

    PageDao dao = new PageDao();


    @GetMapping("search")
    public String FindPageByKeyWord(@RequestParam(required = false, defaultValue = "") String keyword, Model model, HttpSession session) throws IOException {
        Set<PageBean> pages = dao.findPageByKW(keyword, "invertindex_result");
        model.addAttribute("pages", pages);
        model.addAttribute("keyword",keyword);
        return "result";
    }
}
